home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib25 / mntlib25.zoo / atexit.c < prev    next >
C/C++ Source or Header  |  1992-05-15  |  1KB  |  39 lines

  1. /* from Dale Schumacher's dLibs */
  2. /* heavily modified by ers and jrb */
  3. /* and separated from main.c 5/5/92 sb */
  4.  
  5. #include <stddef.h>
  6. #include <stdlib.h>
  7. #include <memory.h>
  8.  
  9. /* functions registered by user for calling at exit */
  10. #ifdef __STDC__
  11. typedef void (*ExitFn)(void);
  12. #else
  13. typedef void (*ExitFn)();
  14. #endif
  15. extern ExitFn *_at_exit;
  16. extern int _num_at_exit;    /* number of functions registered - 1 */
  17.  
  18. /* register a function for execution on termination */
  19. /* Ansi requires atleast 32 entries, we make it dynamic and hope
  20.    it meets the ansi requirement */
  21.  
  22. int atexit(func)
  23.     ExitFn func;
  24. {
  25.         ExitFn *new_at_exit = _at_exit;
  26.     
  27.     if (_num_at_exit == 0)
  28.         new_at_exit = (ExitFn *)malloc((size_t)sizeof(ExitFn));
  29.     else
  30.         new_at_exit = (ExitFn *)realloc(new_at_exit,
  31.             (size_t)((_num_at_exit + 1) * sizeof(ExitFn)));
  32.     if(new_at_exit == (ExitFn *)NULL)
  33.         return -1;    /* failure */
  34.  
  35.         _at_exit = new_at_exit;
  36.     _at_exit[_num_at_exit++] = func;
  37.     return 0;        /* success */
  38. }
  39.